package com.yuyang.wifi.base;

import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.subjects.Subject;

/**
 * Created by wangce on 16/1/18.
 */
public class SuperSubject<T> {

    private Subject<T,T> subject;
    private Class<T> kind;
    private String tag;

    public SuperSubject(Class<T> kind , Subject<T,T> subject , String tag){
        this.kind = kind ;
        this.subject = subject;
        this.tag = tag ;
    }

    public Subject<T, T> getSubject() {
        return subject;
    }

    public Class<T> getGenericClass(){
        return kind;
    }

    public String getTag() {
        return tag;
    }


    public   <T> void observeOnMainThread( final onSubscribe<T> tCall){
        Subject<T,T> subject =  (Subject<T,T>)getSubject();
        subject.observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<T>() {
                    @Override
                    public void call(T s) {
                        tCall.call(s);
                    }
                });
    }


    public interface onSubscribe<T>{
        void call(T s);
    }

}
